//package org.ricks.robot.business;
//
//import org.ricks.common.lang.Logger;
//import org.ricks.common.utils.ThreadUtils;
//import org.ricks.boot.utils.TimeUtils;
//import org.ricks.net.transport.kcp.KcpSession;
//import org.ricks.protocol.ByteBuf;
//import org.ricks.robot.Monitor;
//import org.ricks.robot.RobotInfo;
//import org.ricks.robot.RobotManager;
//import proto.common.*;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
//public class RobotMmoAction {
//
//    public static final Map<RobotInfo, Integer> robotInfoMap = new ConcurrentHashMap<>();
//
//    public static void swing(KcpSession session) {
//
//        FProto fProto = FProto.newBuilder()
//                .setKey(FProto.Key.Scene)
//                .setAction(FProto.Action.Swing)
//                .build();
//
//        byte[] data = fProto.toByteArray();
//
//        ByteBuf buf = new ByteBuf(1024);
//        buf.writeByte((byte) 0x03);
//        buf.writeBytes(data);
//
//        session.send(buf.toArray());
//    }
//
//
//    /**
//     * 房间内玩家行为互相看见 是依赖 2010指令。100ms 发一次同步包
//     * 2011 是小游戏 mmo同步，33ms同步一次 1秒同步30次
//     *
//     * syncRecorderData返回得 code 是 0
//     * @param session
//     */
//    public static void syncRecorderData(KcpSession session) {
//
//        RobotAction.addItem(session, 101001, 1);
//
//        ThreadUtils.sleep(3000L);
//
//        RobotInfo robotInfo = RobotManager.get(session);
//        robotInfo.action = FProto.Action.SyncRecorderData;
//
//        PBVector3 pos = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
//        PBVector3 rot = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
//
//
//        PBSyncRecorderProperty pbSyncRecorderProperty = PBSyncRecorderProperty.newBuilder().setSyncType(1)
//                .setFramestamp(1)
//                .setIsStatic(true)
//                .setForceMove(true)
//                .setPos(pos)
//                .setRot(rot)
//                .setAnimeIsGliding(true)
//                .setAnimeIsDeath(false)
//                .setAnimeIsLooping(true)
//                .setAnimeIsPhone(true)
//                .setAnimeInputSpeed(100f)
//                .setAnimeVerticalSpeed(200f)
//                .addCommonVector3S(pos)
//                .addCommandBools(true)
//                .addCommandFloats(1f)
//                .addCommandInts(1).build();
//
//
//
//
//        PBCharacterRecorderData pbCharacterRecorderData = PBCharacterRecorderData.newBuilder().addDataLst(pbSyncRecorderProperty)
//                .setCharId(101001).build();
//
//        PBPlayerRecorderData pbPlayerRecorderData = PBPlayerRecorderData.newBuilder().addCharRecorderDataLst(pbCharacterRecorderData)
//                .setPlayerId(robotInfo.playerId).build();
//
//        FProto fProto = FProto.newBuilder()
//                .setKey(FProto.Key.Scene)
//                .setAction(FProto.Action.SyncRecorderData)
//                .setRecodeDataModel(pbPlayerRecorderData)
//                .build();
//
//        byte[] data = fProto.toByteArray();
//
//        ByteBuf buf = new ByteBuf(1024);
//        buf.writeByte((byte) 0x03);
//        buf.writeBytes(data);
//
//        session.send(buf.toArray());
//
//    }
//
//
//    public static void syncFrameData(KcpSession session) {
//        RobotInfo robotInfo = RobotManager.get(session);
//        robotInfo.action = FProto.Action.ChannelJump;
//        RobotAction.addItem(session, 101001, 1);
//
////        ThreadUtils.sleep(1000L);
////
////        RobotInfo robotInfo = RobotManager.get(session);
////        robotInfo.action = FProto.Action.SyncRecorderData;
////        int sendCount = robotInfoMap.computeIfAbsent(robotInfo, (r) -> robotInfoMap.put(r, 0)  );
//////        Monitor.addActionRequest(session, FProto.Action.SyncFrameData);
//////        robotInfo.requestTimeMap.put(FProto.Action.SyncFrameData, System.currentTimeMillis());
////
////        PBVector3 pos = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
////        PBVector3 rot = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
////
////        Logger.info(robotInfo + " 开始发出syncFrameData请求");
////        PBSyncRecorderProperty pbSyncRecorderProperty = PBSyncRecorderProperty.newBuilder().setSyncType(1)
////                .setFramestamp(1)
////                .setIsStatic(true)
////                .setForceMove(true)
////                .setPos(pos)
////                .setRot(rot)
////                .setAnimeIsGliding(true)
////                .setAnimeIsDeath(false)
////                .setAnimeIsLooping(true)
////                .setAnimeIsPhone(true)
////                .setAnimeInputSpeed(100f)
////                .setAnimeVerticalSpeed(200f)
////                .addCommonVector3S(pos)
////                .addCommandBools(true)
////                .addCommandFloats(1f)
////                .addCommandInts(1).build();
////
////
////
////
////        PBCharacterRecorderData pbCharacterRecorderData = PBCharacterRecorderData.newBuilder().addDataLst(pbSyncRecorderProperty)
////                .setCharId(101001).build();
////
////        PBPlayerRecorderData pbPlayerRecorderData = PBPlayerRecorderData.newBuilder().addCharRecorderDataLst(pbCharacterRecorderData)
////                .setPlayerId(robotInfo.playerId).build();
////
////        FProto fProto = FProto.newBuilder()
////                .setKey(FProto.Key.Scene)
////                .setAction(FProto.Action.SyncFrameData)
////                .setRecodeDataModel(pbPlayerRecorderData)
////                .setServerTime(TimeUtils.now())
//////                .setErrorTips(robotInfo.robotAccount + sendCount)
////                .build();
////
////        byte[] data = fProto.toByteArray();
////
////        ByteBuf buf = new ByteBuf(1024);
////        buf.writeByte((byte) 0x03);
////        buf.writeBytes(data);
////
////        session.send(buf.toArray());
//    }
//
//
//    public synchronized static void doSyncFrameData(KcpSession session) {
////        RobotAction.addItem(session, 101001, 1);
////
////        ThreadUtils.sleep(1000L);
//
//        RobotInfo robotInfo = RobotManager.get(session);
//        robotInfo.action = FProto.Action.SyncRecorderData;
//        int sendCount = robotInfoMap.getOrDefault(robotInfo, 0) + 1;
//        robotInfoMap.put(robotInfo, sendCount);
////        int sendCount = robotInfoMap.computeIfAbsent(robotInfo, (r) -> robotInfoMap.put(r, 0)  );
////        Monitor.addActionRequest(session, FProto.Action.SyncFrameData);
////        robotInfo.requestTimeMap.put(FProto.Action.SyncFrameData, System.currentTimeMillis());
//
//        PBVector3 pos = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
//        PBVector3 rot = PBVector3.newBuilder().setX(1.0f).setY(1.0f).setZ(100f).build();
//
////        Logger.info(robotInfo + " 开始发出syncFrameData请求");
//        PBSyncRecorderProperty pbSyncRecorderProperty = PBSyncRecorderProperty.newBuilder().setSyncType(1)
//                .setFramestamp(1)
//                .setIsStatic(true)
//                .setForceMove(true)
//                .setPos(pos)
//                .setRot(rot)
//                .setAnimeIsGliding(true)
//                .setAnimeIsDeath(false)
//                .setAnimeIsLooping(true)
//                .setAnimeIsPhone(true)
//                .setAnimeInputSpeed(100f)
//                .setAnimeVerticalSpeed(200f)
//                .addCommonVector3S(pos)
//                .addCommandBools(true)
//                .addCommandFloats(1f)
//                .addCommandInts(1).build();
//
//
//
//
//        PBCharacterRecorderData pbCharacterRecorderData = PBCharacterRecorderData.newBuilder().addDataLst(pbSyncRecorderProperty)
//                .setCharId(101001).build();
//
//        PBPlayerRecorderData pbPlayerRecorderData = PBPlayerRecorderData.newBuilder().addCharRecorderDataLst(pbCharacterRecorderData)
//                .setPlayerId(robotInfo.playerId).build();
//
//        FProto fProto = FProto.newBuilder()
//                .setKey(FProto.Key.Scene)
//                .setAction(FProto.Action.SyncFrameData)
//                .setRecodeDataModel(pbPlayerRecorderData)
//                .setServerTime(System.currentTimeMillis())
//                .setErrorTips(robotInfo.robotAccount +"&" + sendCount)
//                .build();
//
//        byte[] data = fProto.toByteArray();
//
//        ByteBuf buf = new ByteBuf(1024);
//        buf.writeByte((byte) 0x03);
//        buf.writeBytes(data);
//
//        session.send(buf.toArray());
//    }
//}
